import java.util.ArrayList;

/**
	 * This abstract Ship class that contains fields and methods to handle ship object.  
	 * 
	 * @mathmodel each ship has a name and length
	 * @constraint ship size must fit into its type 2, 3, 4 and 5
	 * @mathdef sequence of cell position 
	 * @initially constructor (String name, int length)
	 * @ensures ship = #ship and length = #length
	 * @author vo, wu and wyan
	 * */

public abstract class Ship {
	
	/**
	 * Constant for the position of the ship is horizontal
	 */
	public static final int HORIZONTAL = 0;
	/**
	 * Constant for the position of the ship is vertical
	 */
	public static final int VERTICAL = 1;

	/**
	 * The name of the specific type of the ship
	 */
	private String name;
	
	/**
	 * The length of specific type of the ship
	 */
	private int length;
	
	/**
	 * The number of hit that is being executed by the player
	 */
	private int hitCount;
	
	/**
	 * The array of all cells that contains the ships
	 */
	protected ArrayList<String> cells;
	
	/**
	 * Producing ship type with the appropriate length.
	 * @param name <br />
	 * 			name of the ship
	 * @param length <br />
	 * 			the length that comes if each type of the ship
	 * @require only use the specific type of ships that are allowed to be in the game and the length
	 * @ensure the name of the ship is the correct type of the ship, the length of the ship is correct and 
	 * and the hit count is initialized to 0.  
	 */
	public Ship(String name, int length) {
		this.name = name;
		this.length = length;
		this.hitCount = 0;
		this.cells = new ArrayList<String>();
	}

	/** 
	 * @return the name of the ship. 
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * @return Returns the length of the ship(the cells that the ship used up).
	 */
	public int getLength() {
		return this.length;
	}

	/**
	 * Increase the amount of hit (clicked cell) by 1 point.
	 * @alter hitCount
	 * @ensures hitCount = #hitCount + 1
	 * @return the total of hit count (clicked buttons)
	 */
	public void hit() {
		hitCount++;
	}

	/**
	 * Produce the condition of the ship 
	 * @return true if this ship has been sunk or false otherwise
	 */
	public boolean isSunk() {
		return this.hitCount == length;
	}
	
	/**
	 * Collect all the valid cells where the ships are.
	 * @param shipcell <br />
	 * 			The valid cells where the ships located
	 */
	public void addCell(ArrayList<String> shipcell){
		this.cells = shipcell;
	}

}
